/* -*- Mode: C;  tab-width: 4;  indent-tabs-mode: dunto;  c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software;  you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation;  either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY;  without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program;  if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include "mainprogram.h"

#include <QApplication>
#include <QtSingleApplication>
#include <QTranslator>
#include <QLibraryInfo>
#include <QStyleFactory>
#include <QTextCodec>
#include <QDebug>
#include <QTranslator>
#include <QLibraryInfo>
#include <ukui-log4qt.h>
#include "kysdk/kysdk-system/libkysysinfo.h"

int main(int argc, char *argv[])
{
    initUkuiLog4qt("ukui-bluetooth");

//    QApplication::setStyle(QStyleFactory::create("ukui-default"));
    QApplication::setQuitOnLastWindowClosed(false);
    QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
    QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif

    QtSingleApplication app(argc, argv);

    if (app.isRunning()) {
        qDebug() << "ukui-bluetooth is Already running ! ! !";
        return EXIT_SUCCESS;
    }
    else
    {
        QTranslator *t = new QTranslator();
        t->load("/usr/share/libpeony-qt/libpeony-qt_"+QLocale::system().name() + ".qm");
        QApplication::installTranslator(t);

        //安装ukui-bluetooth的中文翻译
        QTranslator * translator = new QTranslator();;
        translator->load("/usr/share/ukui-bluetooth/translations/ukui-bluetooth_" + QLocale::system().name() + ".qm");
        app.installTranslator(translator);

        //安装Qt中文翻译
        QTranslator * qt_translator = new QTranslator();
        QString qtTransPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
        if (qt_translator->load(QLocale(), "qt", "_", qtTransPath))
            app.installTranslator(qt_translator);

        MainProgram w(envPC);
        if(w.exit_flag){
            return 0;
        }
        return app.exec();
    }
}
